<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>text</title>
    <script type="text/javascript">
        window.onload=function () {
            document.getElementById("btn").onclick=function () {
                document.getElementById("mytext").select();
            }
            document.getElementById("t1").onkeyup=function () {
                checklen(this,this.value);
            }
            document.getElementById("t2").onkeyup=function () {
                checklen(this,this.value);
            }
            document.getElementById("t3").onkeyup=function () {
                checklen(this,this.value);
            }
        }
        function checklen(otext,str) {
            if(str.length==otext.maxLength){
                var inext=otext.tabIndex;
                if (inext<document.getElementById("myform").length){
                    document.getElementById("myform").elements[inext].focus();
                }
            }
        }
    </script>
</head>
<body>
<form>
    <input type="text" size="16" id="mytext" value="选择文本">
    <input type="button" id="btn" value="选择文本">
    <p>到文本框最大长度时自动跳到下一个文本框</p>
</form>
<form id="myform">
    <input size="3" tabindex="1" maxlength="3" id="t1">
    <input size="2" tabindex="2" maxlength="2" id="t2">
    <input size="3" tabindex="3" maxlength="3" id="t3">
</form>
</body>
</html>